<template>
  <div class="card flex transition_0_3" :style="{ width, height }">
    <div class="pic" :style="picStyle"></div>
    <div
      class="content flex flex_column transition_0_3"
      :style="{
        width: `calc(${width} - (${picStyle.width} / 3) )`,
      }"
    >
      <h3 class="title fontsize_28">{{ title }}</h3>
      <div class="text fontsize_20 line_clamp_6" style="height: 200px">
        {{ content }}
      </div>
      <div class="flex flex_row flex_center transition_0_3">
        <div class="flex_1">
          <span class="iconfont ml_10 mr_10 fontsize_20 icon-geren"></span>
          <span class="fontsize_20">{{ author }}</span>
        </div>
        <div class="flex_1">
          <span class="iconfont ml_10 mr_10 fontsize_20 icon-shijian"></span>
          <span class="fontsize_20">{{ time }}</span>
        </div>
        <div class="flex_1">
          <span class="iconfont ml_10 mr_10 fontsize_20 icon-pinglun"></span>
          <span class="fontsize_20">{{ comments }}</span>
          <span class="iconfont ml_10 mr_10 fontsize_24 icon-yizan"></span>
          <span class="fontsize_20">{{ praise }}</span>
        </div>
        <div class="ml_10">
          <ShadowBox
            width="200px"
            height="40px"
            borderWidth="4px"
            color="#333"
            plain
            center
            btn
            style="user-select: none; cursor: pointer"
            :bindClick="toDetail"
          >
            &gt;&gt; 查看详情 &lt;&lt;
          </ShadowBox>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ShadowBox from "../components/shadowBox.vue";
export default {
  name: "Card",
  components: {
    ShadowBox,
  },
  props: {
    extends:{
      type: Object,
      default: () => ({
      }),
    },
    title: {
      type: String,
      default: "",
    },
    content: {
      type: String,
      default: "",
    },
    author: {
      type: String,
      default: "",
    },
    time: {
      type: String,
      default: "",
    },
    comments: {
      type: String,
      default: "",
    },
    praise: {
      type: String,
      default: "",
    },
    img: {
      type: String,
      default: "",
    },
    link: {
      type: String,
      default: "",
    },
    width: {
      type: String,
      default: "700px",
    },
    height: {
      type: String,
      default: "100%",
    },
  },
  data() {
    return {};
  },
  computed: {
    picStyle() {
      return {
        width: `calc(${this.height} - 30px)`,
        height: `calc(${this.height} - 30px)`,
        backgroundImage: `url(${
          this.img || require("../assets/images/guide.jpg")
        })`,
      };
    },
  },
  methods: {
    toDetail() {
      window.localStorage.setItem("detail", JSON.stringify(this.extends));
      this.$router.push('/articleDetail');
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../style/theme.scss";
.card {
  border: 4px solid #eee;
  border-radius: 10px;
  background: #fff;

  &:hover {
    border: 4px solid $blue-500;
    border-radius: 10px;
    background: #fff;
    box-shadow: 4px 4px 10px 10px rgba(0, 0, 0, 0.1),
      -4px -4px 10px 10px rgba(255, 255, 255, 0.1);
  }
  .pic {
    margin: 10px;
    width: 200px;
    height: 200px;
    border-radius: 10px;
    background-color: #f8f8f8;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
  }
  .content {
    padding: 10px;
    .title {
      font-weight: bold;
      margin-bottom: 10px;
    }
    .text {
      line-height: 1.6;
      white-space: pre-wrap;
    }
  }
}
</style>